Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Supplier] Implement unbonding period #666

Merged
merged 20 commits into from
Jul 25, 2024
Merged

[Supplier] Implement unbonding period #666

merged 20 commits into from
Jul 25, 2024

Conversation

red-0ne
Copy link
Contributor

@red-0ne red-0ne commented Jul 8, 2024

Summary

This PR adds an unbonding period when a Supplier submits an unstaking transaction.

  • Adds an unbondingHeight to the Supplier proto.
  • Resets the unbondingHeight when a supplier re-stakes during that period.
  • Adds a stateless function that calculates the unbondingHeight for a given height.
  • Prevents unstake transactions of Suppliers that are already in an unbonding period.
  • Adds an EndBlocker routine to effectively unbond Suppliers that reached their unbonding height.
  • Keeps the Suppliers normally functioning during the unbonding period.

Issue

Suppliers that submit an unstake transaction have to wait for a certain time before getting their staked funds back.

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

Documentation changes (only if making doc changes)

  • make docusaurus_start; only needed if you make doc changes

Local Testing (only if making code changes)

  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • See quickstart guide for instructions

PR Testing (only if making code changes)

  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.
    • THIS IS VERY EXPENSIVE, so only do it after all the reviews are complete.
    • Optionally run make trigger_ci if you want to re-trigger tests without any code changes
    • If tests fail, try re-running failed tests only using the GitHub UI as shown here

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

Summary by CodeRabbit

  • New Features

    • Introduced a mechanism to handle supplier unstaking with checks for previous unstaking actions and updated session end height parameters.
    • Added EndBlockerUnbondSuppliers function to manage supplier unbonding at session end.
    • Implemented new methods to determine supplier unbonding status and activity based on specific conditions.
    • Created a function to calculate the unbonding height for suppliers based on input parameters.
  • Bug Fixes

    • Improved unstaking logic to prevent immediate supplier removal.
  • Tests

    • Enhanced test coverage for scenarios like canceling unbonding if restaked and failure if not in the unbonding period.
  • Chores

    • Added new error handling and validation logic related to supplier functionalities.

@red-0ne red-0ne added supplier Changes related to the Supplier actor on-chain On-chain business logic labels Jul 8, 2024
@red-0ne red-0ne self-assigned this Jul 8, 2024
Copy link

coderabbitai bot commented Jul 8, 2024

Walkthrough

The recent updates to the supplier module enhance the unstaking process, introducing checks for prior unstaking actions and the ability to cancel unbonding when a supplier is restaked. A new sharedKeeper facilitates better coordination across modules, improving the management of shared parameters and session information. Additionally, expanded test cases ensure robust handling of supplier interactions within the module.

Changes

Files Change Summaries
x/supplier/keeper/... Enhanced unstaking logic with checks for prior actions, session end height settings, and revamped test cases for new scenarios.
x/supplier/keeper/unbond_suppliers.go Introduced EndBlockerUnbondSuppliers function to manage supplier unbonding at session end.
x/supplier/keeper/keeper.go Added sharedKeeper field to the Keeper struct and updated NewKeeper for better integration.
x/supplier/types/errors.go Introduced two new errors: ErrSupplierIsUnstaking and ErrSupplierParamsInvalid.
x/supplier/types/params.go Added global variables for unbonding periods and validations, enhancing the ParamSet interface.
e2e/tests/init_test.go Added helper functions to manage unbonding scenarios within supplier tests.
testutil/integration/app.go Modified context setup to include sharedKeeper, improving integration for testing.
testutil/keeper/proof.go Included sharedKeeper parameter in NewProofModuleKeepers function for comprehensive testing.
x/session/keeper/session_hydrator.go Implemented logic to exclude suppliers in unbonding periods based on block heights.
x/supplier/module/module.go Renamed keeper to supplierKeeper in AppModule struct and updated method calls for clarity.
x/shared/types/supplier.go Implemented IsUnbonding and IsActive methods in Supplier struct and defined the constant SupplierNotUnstaking.
x/shared/supplier.go Created GetSupplierUnbondingHeight function for calculating the unbonding height of suppliers.
testutil/keeper/supplier.go Updated imports and initialized sharedKeeper in the SupplierKeeper function to enhance testing capabilities.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c77015a and cadef6c.

Files selected for processing (1)
  • x/shared/supplier.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/shared/supplier.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@red-0ne red-0ne marked this pull request as ready for review July 10, 2024 03:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Outside diff range and nitpick comments (7)
x/supplier/keeper/keeper.go (1)

24-25: Add documentation for new fields.

Consider adding comments to document the purpose of the bankKeeper and sharedKeeper fields for better maintainability and readability.

// bankKeeper is responsible for handling bank-related operations.
bankKeeper   types.BankKeeper
// sharedKeeper is responsible for handling shared operations across modules.
sharedKeeper types.SharedKeeper
x/supplier/keeper/msg_update_params_test.go (1)

33-39: Enhance test descriptions.

The test descriptions can be more descriptive to provide better context about the test cases.

- desc: "invalid: send empty params"
+ desc: "invalid: params should not be empty"
testutil/keeper/supplier.go (1)

72-74: Clarify the purpose of moving block height to 1.

Explain why the block height is moved to 1 to provide context for future maintainers.

-  // Move block height to 1 to get a non zero session end height
+  // Move block height to 1 to ensure session end height is non-zero for testing purposes
x/supplier/keeper/msg_server_stake_supplier.go (1)

52-53: Add a comment explaining the reset of UnstakeCommitSessionEndHeight.

Adding a comment will help future maintainers understand why this reset is necessary.

-    supplier.UnstakeCommitSessionEndHeight = 0
+    // Reset the UnstakeCommitSessionEndHeight as the supplier is staking again.
+    supplier.UnstakeCommitSessionEndHeight = 0
x/supplier/keeper/msg_server_unstake_supplier_test.go (2)

Line range hint 28-63:
Ensure proper block height increment for unbonding period.

The test correctly verifies the supplier unbonding process, but it would be clearer to explicitly increment the block height by the unbonding period instead of setting it directly.

- sdkCtx = sdkCtx.WithBlockHeight(unbondingHeight)
+ sdkCtx = sdkCtx.WithBlockHeight(sdkCtx.BlockHeight() + int64(k.GetParams(ctx).SupplierUnbondingPeriodBlocks))

67-118: Ensure proper block height increment for unbonding period.

The test correctly verifies the cancellation of the unbonding period upon restaking. It would be clearer to explicitly increment the block height by the unbonding period instead of setting it directly.

- sdkCtx = sdkCtx.WithBlockHeight(unbondingHeight)
+ sdkCtx = sdkCtx.WithBlockHeight(sdkCtx.BlockHeight() + int64(k.GetParams(ctx).SupplierUnbondingPeriodBlocks))
x/supplier/types/genesis_test.go (1)

Line range hint 62-352:
Ensure test descriptions are clear and consistent.

The test cases for the genesis state validation are comprehensive. However, the description for the "invalid - zero supplier unbonding period blocks" test case could be more descriptive.

- desc: "invalid - zero supplier unbonding period blocks",
+ desc: "invalid - supplier unbonding period blocks set to zero",
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdbc365 and 94f078f.

Files ignored due to path filters (2)
  • x/shared/types/supplier.pb.go is excluded by !**/*.pb.go
  • x/supplier/types/params.pb.go is excluded by !**/*.pb.go
Files selected for processing (27)
  • api/poktroll/shared/supplier.pulsar.go (16 hunks)
  • api/poktroll/supplier/params.pulsar.go (14 hunks)
  • e2e/tests/init_test.go (2 hunks)
  • e2e/tests/session_steps_test.go (1 hunks)
  • e2e/tests/stake_app.feature (2 hunks)
  • e2e/tests/stake_gateway.feature (2 hunks)
  • e2e/tests/stake_supplier.feature (2 hunks)
  • proto/poktroll/shared/supplier.proto (1 hunks)
  • proto/poktroll/supplier/params.proto (1 hunks)
  • testutil/integration/app.go (4 hunks)
  • testutil/keeper/proof.go (1 hunks)
  • testutil/keeper/supplier.go (3 hunks)
  • testutil/keeper/tokenomics.go (1 hunks)
  • x/session/keeper/session_hydrator.go (1 hunks)
  • x/supplier/keeper/keeper.go (3 hunks)
  • x/supplier/keeper/msg_server_stake_supplier.go (1 hunks)
  • x/supplier/keeper/msg_server_unstake_supplier.go (2 hunks)
  • x/supplier/keeper/msg_server_unstake_supplier_test.go (4 hunks)
  • x/supplier/keeper/msg_update_params_test.go (1 hunks)
  • x/supplier/keeper/unbond_suppliers.go (1 hunks)
  • x/supplier/module/abci.go (1 hunks)
  • x/supplier/module/module.go (6 hunks)
  • x/supplier/module/simulation.go (3 hunks)
  • x/supplier/types/errors.go (1 hunks)
  • x/supplier/types/expected_keepers.go (2 hunks)
  • x/supplier/types/genesis_test.go (14 hunks)
  • x/supplier/types/params.go (3 hunks)
Additional comments not posted (67)
x/supplier/module/abci.go (1)

1-16: LGTM!

The EndBlocker function correctly integrates the unbonding logic by calling EndBlockerUnbondSupplier from the keeper package. The changes are approved.

proto/poktroll/supplier/params.proto (1)

13-16: LGTM!

The supplier_unbonding_period_blocks field is correctly added to the Params message with appropriate comments and annotations. The changes are approved.

proto/poktroll/shared/supplier.proto (1)

16-16: LGTM!

The unstake_commit_session_end_height field is correctly added to the Supplier message with appropriate comments. The changes are approved.

x/supplier/types/expected_keepers.go (1)

25-29: LGTM!

The SharedKeeper interface is correctly defined with methods to retrieve shared parameters and session end height information. The changes are approved.

x/supplier/keeper/keeper.go (2)

36-36: Ensure proper initialization and usage of sharedKeeper.

The sharedKeeper is a new dependency added to the NewKeeper function. Ensure that this dependency is correctly initialized and used throughout the codebase to avoid potential runtime issues.


48-49: LGTM!

The addition of sharedKeeper to the Keeper struct and its initialization in the constructor looks good.

x/supplier/types/errors.go (1)

19-20: LGTM!

The addition of ErrSupplierUnbonding and ErrSupplierParamsInvalid error types looks good. These errors will help in handling specific conditions related to the supplier unbonding period and invalid parameters.

x/supplier/keeper/msg_update_params_test.go (1)

41-48: LGTM!

The addition of the test case for Zero SupplierUnbondingPeriodBlocks looks good. This ensures that the parameter is validated correctly.

e2e/tests/stake_gateway.feature (2)

11-11: LGTM!

The addition of the step to wait for the StakeGateway message to be submitted looks good. This ensures that the staking process is completed before proceeding.


23-23: LGTM!

The addition of the step to wait for the UnstakeGateway message to be submitted looks good. This ensures that the unstaking process is completed before proceeding.

e2e/tests/stake_app.feature (2)

13-13: Ensure the new step is correctly implemented.

The step And the user should wait for the "application" module "StakeApplication" message to be submitted is added. Verify that the implementation of this step correctly waits for the message.


25-25: Ensure the new step is correctly implemented.

The step And the user should wait for the "application" module "UnstakeApplication" message to be submitted is added. Verify that the implementation of this step correctly waits for the message.

e2e/tests/stake_supplier.feature (2)

13-13: Ensure the new step is correctly implemented.

The step And the user should wait for the "supplier" module "StakeSupplier" message to be submitted is added. Verify that the implementation of this step correctly waits for the message.


25-27: Ensure the new steps for unbonding are correctly implemented.

The steps for handling the unbonding process are added. Verify that the implementation of these steps correctly handles the unbonding period and transitions.

x/supplier/types/params.go (6)

3-5: Ensure the imports are necessary.

The added imports are necessary for the parameter types. No issues here.


7-13: Ensure the new parameter is correctly defined and initialized.

The new parameter SupplierUnbondingPeriodBlocks is defined and initialized with a default value. Ensure that the default value is appropriate and that the TODO comment is addressed before merging.


22-24: Ensure the new parameter is correctly initialized in NewParams.

The new parameter SupplierUnbondingPeriodBlocks is initialized with the default value. No issues here.


34-40: Ensure the new parameter is correctly added to ParamSetPairs.

The new parameter SupplierUnbondingPeriodBlocks is added to ParamSetPairs with the appropriate validation function. No issues here.


45-51: Ensure the new parameter is correctly validated in Validate.

The validation logic for the new parameter SupplierUnbondingPeriodBlocks is correctly added to the Validate method. No issues here.


53-65: Ensure the new validation function is correctly implemented.

The validation function for the new parameter SupplierUnbondingPeriodBlocks is correctly implemented. Ensure that the error messages are clear and that the validation logic is appropriate.

x/supplier/keeper/msg_server_unstake_supplier.go (3)

10-10: Ensure the new import is necessary.

The import for the shared package is necessary for accessing shared parameters. No issues here.


41-44: Ensure the check for the unbonding period is correctly implemented.

The check for whether the supplier is already in the unbonding period is correctly implemented. No issues here.


47-59: Ensure the logic for setting the unbonding height is correctly implemented.

The logic for setting the UnstakeCommitSessionEndHeight based on the current height and shared parameters is correctly implemented. No issues here.

testutil/keeper/supplier.go (1)

51-59: Ensure shared keeper parameters are set correctly.

Verify that the parameters for the shared keeper are set correctly and consider adding error handling for potential issues.

x/supplier/module/simulation.go (2)

70-70: Ensure staking simulation function is implemented correctly.

Verify that the SimulateMsgStakeSupplier function is implemented correctly and handles all necessary logic.


81-81: Ensure unstaking simulation function is implemented correctly.

Verify that the SimulateMsgUnstakeSupplier function is implemented correctly and handles all necessary logic.

x/supplier/keeper/msg_server_stake_supplier.go (1)

52-53: Ensure unstake action is correctly canceled.

Verify that the logic for canceling the unstake action when a supplier stakes again is correct and handles all necessary conditions.

x/supplier/keeper/msg_server_unstake_supplier_test.go (3)

Line range hint 131-138:
LGTM!

The test correctly verifies the error handling for unstaking a non-existent supplier.


141-164: LGTM!

The test correctly verifies the error handling for unstaking outside the unbonding period.


166-186: LGTM!

The helper function correctly constructs a stake message for testing purposes.

x/supplier/module/module.go (5)

Line range hint 98-113:
LGTM!

The function correctly initializes a new AppModule with the added supplierKeeper.


119-120: LGTM!

The function correctly registers the gRPC services for the supplier module.


132-132: LGTM!

The function correctly initializes the genesis state for the supplier module.


137-137: LGTM!

The function correctly exports the genesis state for the supplier module.


154-156: LGTM!

The function correctly handles the end block logic for the supplier module.

testutil/keeper/proof.go (1)

189-189: LGTM!

The function correctly initializes the ProofModuleKeepers with the added sharedKeeper.

x/session/keeper/session_hydrator.go (1)

175-179: Exclude suppliers in unbonding period

This logic correctly excludes suppliers whose UnstakeCommitSessionEndHeight is set and whose unbonding period has ended before the session end block height. This ensures that only suppliers that are fully available are included in the session.

testutil/keeper/tokenomics.go (1)

293-293: Add sharedKeeper to supplier keeper

The sharedKeeper parameter has been correctly added to the supplier keeper initialization. This ensures that the supplier keeper has access to shared parameters and functionality.

e2e/tests/session_steps_test.go (3)

254-281: Add waitForBlockHeight function

This function correctly waits for a block height to be reached by subscribing to new block events. It ensures that the target height is reached before proceeding, which is essential for handling time-based events in tests.


Line range hint 445-457:
Check if supplier is unbonding

This function correctly checks if a supplier is in the unbonding period by verifying that UnstakeCommitSessionEndHeight is greater than zero. This ensures that the supplier's unbonding status is accurately determined.


Line range hint 459-465:
Wait for unbonding period to finish

This function correctly waits for the unbonding period to finish by waiting for the block height to reach the supplier's unbonding height. This ensures that the tests account for the unbonding period before proceeding.

e2e/tests/init_test.go (2)

591-609: Retrieve supplier information

This function correctly retrieves supplier information by querying the supplier module and unmarshalling the response. This ensures that the tests have access to accurate supplier data.


611-629: Calculate supplier unbonding height

This function correctly calculates the supplier's unbonding height by adding the unbonding period blocks to the UnstakeCommitSessionEndHeight. This ensures that the tests can accurately determine when the unbonding period will end.

api/poktroll/supplier/params.pulsar.go (7)

18-19: Field Descriptor Added: fd_Params_supplier_unbonding_period_blocks

The field descriptor for supplier_unbonding_period_blocks is correctly added to the Params struct.


25-25: Field Descriptor Initialization: fd_Params_supplier_unbonding_period_blocks

The field descriptor for supplier_unbonding_period_blocks is correctly initialized in the init function.


93-98: Field Added to Range Method: supplier_unbonding_period_blocks

The supplier_unbonding_period_blocks field is correctly added to the Range method.


114-115: Field Added to Has Method: supplier_unbonding_period_blocks

The supplier_unbonding_period_blocks field is correctly added to the Has method.


132-133: Field Added to Clear Method: supplier_unbonding_period_blocks

The supplier_unbonding_period_blocks field is correctly added to the Clear method.


150-152: Field Added to Get Method: supplier_unbonding_period_blocks

The supplier_unbonding_period_blocks field is correctly added to the Get method.


173-174: Field Added to Set Method: supplier_unbonding_period_blocks

The supplier_unbonding_period_blocks field is correctly added to the Set method.

testutil/integration/app.go (3)

341-341: Parameter Added: sharedKeeper to supplierKeeper

The sharedKeeper parameter is correctly added to the supplierKeeper.


473-476: Function Call: NextBlock to Finalize Genesis and Setup

The NextBlock function call is correctly placed to finalize genesis and setup.


711-714: Context Update: Next Block

The context update to the next block is correctly done.

api/poktroll/shared/supplier.pulsar.go (14)

69-73: Declaration of new field descriptor looks good.

The addition of fd_Supplier_unstake_commit_session_end_height is consistent with protobuf conventions.


82-82: Initialization of new field descriptor looks good.

The initialization of fd_Supplier_unstake_commit_session_end_height in the init function is correctly implemented.


168-173: Inclusion of new field in Range method looks good.

The addition of UnstakeCommitSessionEndHeight in the Range method ensures proper iteration over the field.


195-196: Inclusion of new field in Has method looks good.

The addition of UnstakeCommitSessionEndHeight in the Has method ensures proper checking for the presence of the field.


219-220: Inclusion of new field in Clear method looks good.

The addition of UnstakeCommitSessionEndHeight in the Clear method ensures proper clearing of the field.


249-251: Inclusion of new field in Get method looks good.

The addition of UnstakeCommitSessionEndHeight in the Get method ensures proper retrieval of the field.


280-281: Inclusion of new field in Set method looks good.

The addition of UnstakeCommitSessionEndHeight in the Set method ensures proper setting of the field.


315-316: Inclusion of new field in Mutable method looks good.

The addition of UnstakeCommitSessionEndHeight in the Mutable method ensures proper handling of the field as non-mutable.


338-339: Inclusion of new field in NewField method looks good.

The addition of UnstakeCommitSessionEndHeight in the NewField method ensures proper initialization of the field.


423-425: Inclusion of new field in ProtoMethods size function looks good.

The addition of UnstakeCommitSessionEndHeight in the size function ensures proper size calculation.


455-459: Inclusion of new field in ProtoMethods marshal function looks good.

The addition of UnstakeCommitSessionEndHeight in the marshal function ensures proper marshaling of the field.


648-666: Inclusion of new field in ProtoMethods unmarshal function looks good.

The addition of UnstakeCommitSessionEndHeight in the unmarshal function ensures proper unmarshaling of the field.


721-724: Addition of new field to Supplier struct looks good.

The addition of UnstakeCommitSessionEndHeight to the Supplier struct is correctly implemented.


768-773: Addition of getter method for new field looks good.

The addition of GetUnstakeCommitSessionEndHeight ensures proper access to the new field.

x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @red-0ne! 🙌 🚀

e2e/tests/stake_app.feature Show resolved Hide resolved
proto/poktroll/shared/supplier.proto Outdated Show resolved Hide resolved
testutil/integration/app.go Show resolved Hide resolved
testutil/integration/app.go Show resolved Hide resolved
testutil/keeper/supplier.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/supplier/types/errors.go Outdated Show resolved Hide resolved
x/supplier/types/params.go Outdated Show resolved Hide resolved
x/supplier/types/params.go Outdated Show resolved Hide resolved
@red-0ne red-0ne requested a review from bryanchriswhite July 12, 2024 22:18
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 94f078f and aa26347.

Files ignored due to path filters (1)
  • x/shared/types/supplier.pb.go is excluded by !**/*.pb.go
Files selected for processing (11)
  • api/poktroll/shared/supplier.pulsar.go (16 hunks)
  • e2e/tests/init_test.go (2 hunks)
  • proto/poktroll/shared/supplier.proto (1 hunks)
  • testutil/keeper/supplier.go (3 hunks)
  • x/session/keeper/session_hydrator.go (1 hunks)
  • x/supplier/keeper/msg_server_stake_supplier.go (1 hunks)
  • x/supplier/keeper/msg_server_unstake_supplier.go (2 hunks)
  • x/supplier/keeper/msg_server_unstake_supplier_test.go (4 hunks)
  • x/supplier/keeper/unbond_suppliers.go (1 hunks)
  • x/supplier/types/errors.go (1 hunks)
  • x/supplier/types/params.go (3 hunks)
Files skipped from review as they are similar to previous changes (9)
  • api/poktroll/shared/supplier.pulsar.go
  • e2e/tests/init_test.go
  • proto/poktroll/shared/supplier.proto
  • testutil/keeper/supplier.go
  • x/supplier/keeper/msg_server_stake_supplier.go
  • x/supplier/keeper/msg_server_unstake_supplier.go
  • x/supplier/keeper/msg_server_unstake_supplier_test.go
  • x/supplier/keeper/unbond_suppliers.go
  • x/supplier/types/params.go
Additional comments not posted (7)
x/supplier/types/errors.go (2)

19-19: LGTM!

The error ErrSupplierIsUnstaking is clear and consistent with the new unbonding period feature.


20-20: LGTM!

The error ErrSupplierParamsInvalid is clear and consistent with the error handling improvements.

x/session/keeper/session_hydrator.go (5)

175-175: LGTM!

The check to exclude suppliers that are in an unbonding period is consistent with the new unbonding period feature.


176-177: LGTM!

The TODO comment regarding newly staked suppliers joining sessions immediately highlights a potential issue that needs to be addressed in the future.


178-179: LGTM!

The check for UnstakeCommitSessionEndHeight ensures that suppliers who are unstaking are not included in the session's suppliers list.


180-180: LGTM!

The continuation of the check for UnstakeCommitSessionEndHeight ensures that the logic is complete and consistent.


181-182: LGTM!

The blank line improves the readability of the code.

Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Preemptively approving. I still think we should do a find and replace likes/unbonding/unstaking/g, and there was one import alias I think should be renamed. Otherwise this LGTM. 🔥🔥🔥 🚒

x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
Copy link

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 666)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Jul 15, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aa26347 and 1616f96.

Files selected for processing (1)
  • x/supplier/keeper/unbond_suppliers.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/supplier/keeper/unbond_suppliers.go

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1f2da17 and 803567a.

Files selected for processing (11)
  • testutil/integration/app.go (4 hunks)
  • testutil/keeper/proof.go (1 hunks)
  • testutil/keeper/supplier.go (4 hunks)
  • testutil/keeper/tokenomics.go (1 hunks)
  • x/session/keeper/session_hydrator.go (2 hunks)
  • x/supplier/keeper/keeper.go (3 hunks)
  • x/supplier/keeper/msg_server_stake_supplier.go (1 hunks)
  • x/supplier/module/module.go (7 hunks)
  • x/supplier/module/simulation.go (3 hunks)
  • x/supplier/types/errors.go (1 hunks)
  • x/supplier/types/expected_keepers.go (1 hunks)
Files skipped from review as they are similar to previous changes (11)
  • testutil/integration/app.go
  • testutil/keeper/proof.go
  • testutil/keeper/supplier.go
  • testutil/keeper/tokenomics.go
  • x/session/keeper/session_hydrator.go
  • x/supplier/keeper/keeper.go
  • x/supplier/keeper/msg_server_stake_supplier.go
  • x/supplier/module/module.go
  • x/supplier/module/simulation.go
  • x/supplier/types/errors.go
  • x/supplier/types/expected_keepers.go

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review. Will continue tomorrow.

testutil/keeper/supplier.go Outdated Show resolved Hide resolved
x/session/keeper/session_hydrator.go Outdated Show resolved Hide resolved
x/session/keeper/session_hydrator.go Outdated Show resolved Hide resolved
proto/poktroll/shared/supplier.proto Outdated Show resolved Hide resolved
x/supplier/types/params.go Outdated Show resolved Hide resolved
x/supplier/module/abci.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
var resp sharedtypes.QueryParamsResponse
responseBz := []byte(strings.TrimSpace(res.Stdout))
s.cdc.MustUnmarshalJSON(responseBz, &resp)
windowCloseHeight := shared.GetProofWindowCloseHeight(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we get this from the supplier field?

Copy link
Contributor Author

@red-0ne red-0ne Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The supplier has the SessionEndHeight of the block at which the MsgUnstake tx was committed.
I'll try storing the UnbondingHeight to see if its better API.

The reason for storing UnstakeSessionEndHeight and not the windowCloseHeight is that we need the former to know whether the Supplier is still active or not.

Storing the additional windowCloseHeight/UnbondingHeight would be redundant since we can derive it from UnstakeSessionEndHeight.

As @bryanchriswhite suggested, Having a static function to get the UnbondingHeight should be the way to go.

e2e/tests/session_steps_test.go Show resolved Hide resolved
// Exclude suppliers that are in an unbonding period.
// TODO_TECHDEBT: Suppliers that stake mid-session SHOULD NOT be included
// in the current session's suppliers list and must wait until the next one.
if s.UnstakeCommitSessionEndHeight != suppliertypes.SupplierNotUnstaking &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we create a func (s *Supplier) isUnbonding() bool function as a helper?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have to take a height argument.

func (s *Supplier) isUnbonding(queryHeight int64) bool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryanchriswhite, I think there's a nuance here that needs to be considered given the value of UnstakeSessionEndHeight:

  • 0: never unstaked
  • != 0 && < currentSessionEnd: initiated an unstake but still active (serving relays)
  • > currentSessionEnd: is unbonding and no longer active (serving relays)

I believe IsUnbonding should only indicate if the supplier initiated an unstake, and not whether it's sill active or not. This would maximize the reusablility of the method.

Given that, it's signature should be IsUnbonding() bool and should not take the height as argument.

We could still have a IsActive(queryHeight) bool that Indicates whether it should be included in sessions or not.

x/supplier/keeper/msg_server_unstake_supplier.go Outdated Show resolved Hide resolved
// Removing it right away could have undesired effects on the network
// (e.g. a session with less than the minimum or 0 number of suppliers,
// off-chain actors that need to listen to session supplier's change mid-session, etc).
supplier.UnstakeCommitSessionEndHeight = uint64(shared.GetSessionEndHeight(&sharedParams, currentHeight))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be based on a governance param based on the original ticket.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not storing when the unbonding should be effective, but rather when the Supplier becomes inactive.

The unbonding height is derived from this one at the EndBlocker level.

x/supplier/keeper/unbond_suppliers.go Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
e2e/tests/init_test.go Outdated Show resolved Hide resolved
x/session/keeper/session_hydrator.go Outdated Show resolved Hide resolved
// Exclude suppliers that are in an unbonding period.
// TODO_TECHDEBT: Suppliers that stake mid-session SHOULD NOT be included
// in the current session's suppliers list and must wait until the next one.
if s.UnstakeCommitSessionEndHeight != suppliertypes.SupplierNotUnstaking &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have to take a height argument.

func (s *Supplier) isUnbonding(queryHeight int64) bool

e2e/tests/init_test.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Show resolved Hide resolved
x/supplier/keeper/msg_server_unstake_supplier_test.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/supplier/types/params.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
x/shared/types/supplier.go (1)

11-13: Add comments explaining the logic.

To improve readability, add comments explaining the logic of the function.

func (s *Supplier) IsActive(queryHeight int64) bool {
+  // A supplier is active if it is not unbonding or if the query height is within the unbonding period
	return !s.IsUnbonding() || uint64(queryHeight) <= s.UnstakeSessionEndHeight
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 803567a and f4b5c95.

Files ignored due to path filters (1)
  • x/shared/types/supplier.pb.go is excluded by !**/*.pb.go
Files selected for processing (12)
  • api/poktroll/shared/supplier.pulsar.go (16 hunks)
  • e2e/tests/init_test.go (3 hunks)
  • proto/poktroll/shared/supplier.proto (1 hunks)
  • testutil/keeper/supplier.go (4 hunks)
  • x/session/keeper/session_hydrator.go (1 hunks)
  • x/shared/supplier.go (1 hunks)
  • x/shared/types/supplier.go (1 hunks)
  • x/supplier/keeper/msg_server_stake_supplier.go (1 hunks)
  • x/supplier/keeper/msg_server_unstake_supplier.go (2 hunks)
  • x/supplier/keeper/msg_server_unstake_supplier_test.go (3 hunks)
  • x/supplier/keeper/unbond_suppliers.go (1 hunks)
  • x/supplier/module/abci.go (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • api/poktroll/shared/supplier.pulsar.go
  • e2e/tests/init_test.go
  • proto/poktroll/shared/supplier.proto
  • testutil/keeper/supplier.go
  • x/session/keeper/session_hydrator.go
  • x/supplier/keeper/msg_server_stake_supplier.go
  • x/supplier/keeper/msg_server_unstake_supplier.go
  • x/supplier/keeper/msg_server_unstake_supplier_test.go
  • x/supplier/keeper/unbond_suppliers.go
  • x/supplier/module/abci.go
Additional comments not posted (2)
x/shared/types/supplier.go (2)

3-5: LGTM!

The constant SupplierNotUnstaking is correctly defined.


7-9: LGTM!

The function IsUnbonding is correctly implemented.

x/shared/supplier.go Outdated Show resolved Hide resolved
x/shared/types/supplier.go Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/shared/types/supplier.go Show resolved Hide resolved
@red-0ne red-0ne requested a review from bryanchriswhite July 22, 2024 17:06
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f4b5c95 and 304fc70.

Files selected for processing (1)
  • x/shared/types/supplier.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/shared/types/supplier.go

x/supplier/module/abci.go Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Show resolved Hide resolved
x/shared/supplier.go Show resolved Hide resolved
x/shared/types/supplier.go Outdated Show resolved Hide resolved
x/shared/types/supplier.go Show resolved Hide resolved
e2e/tests/init_test.go Show resolved Hide resolved
x/shared/supplier.go Show resolved Hide resolved
x/supplier/keeper/unbond_suppliers.go Outdated Show resolved Hide resolved
x/shared/types/supplier.go Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

x/supplier/module/abci.go Show resolved Hide resolved
x/shared/types/supplier.go Show resolved Hide resolved
@red-0ne red-0ne requested a review from Olshansk July 23, 2024 13:50
x/shared/supplier.go Outdated Show resolved Hide resolved
@red-0ne red-0ne merged commit 6d466c6 into main Jul 25, 2024
10 checks passed
okdas pushed a commit that referenced this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devnet devnet-test-e2e on-chain On-chain business logic push-image CI related - pushes images to ghcr.io supplier Changes related to the Supplier actor
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants